﻿using EasyAbp.Abp.SettingUi;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SandAbp.Dictionary;
using SandAbp.Openiddict;
using SandAbp.ScheduleTask;
using Volo.Abp.Account;
using Volo.Abp.AutoMapper;
using Volo.Abp.BlobStoring;
using Volo.Abp.BlobStoring.FileSystem;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement;
using Volo.Abp.SettingManagement;
using Volo.Abp.TenantManagement;
using WeChat.CMS.Attachments;

namespace WeChat.CMS;

[DependsOn(
    typeof(AbpSettingUiApplicationModule),
    typeof(CMSDomainModule),
    typeof(AbpAccountApplicationModule),
    typeof(CMSApplicationContractsModule),
    typeof(AbpIdentityApplicationModule),
    typeof(AbpPermissionManagementApplicationModule),
    typeof(AbpTenantManagementApplicationModule),
    typeof(AbpFeatureManagementApplicationModule),
    typeof(AbpSettingManagementApplicationModule),
    typeof(AbpBlobStoringModule),
    typeof(AbpBlobStoringFileSystemModule),
    typeof(DictionaryApplicationModule),
    typeof(ScheduleTaskApplicationModule),
    typeof(OpeniddictApplicationModule)
    )]
public class CMSApplicationModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var config = context.Services.GetConfiguration();
        var blobBasePath = config["Blob:FilePath"]?.ToString();
        Configure<AbpAutoMapperOptions>(options =>
        {
            options.AddMaps<CMSApplicationModule>();
        });

        Configure<AbpBlobStoringOptions>(options =>
        {
            options.Containers.Configure<AttachmentContainer>(container =>
            {
                container.UseFileSystem(fileSystem =>
                {
                    fileSystem.BasePath = blobBasePath;
                });
              
                container.IsMultiTenant = true;
            });
        });
    }
}
